/*
 * @Description: 
 * @Version: 
 * @Autor: LiChuang
 * @Date: 2024-05-22 14:35:04
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-05-24 08:51:48
 */
import axios from 'axios';

import * as cheerio from 'cheerio';

// import logo from '../assets/logo.png'
// const urls  = chrome.runtime.getURL(logo)

// const imgDom = document.getElementsByClassName('logo-trends-wrapper_150M5')[0].getElementsByTagName('img')[0]
// imgDom.setAttribute('src',urls) 
//设置主题
const setBg = () => {
    return document.documentElement.style.filter = "hue-rotate(180deg)"
}

setBg()

const url = 'https://top.baidu.com/board?tab=realtime';

axios.get(url)
  .then(function (response) {
    const $ = cheerio.load(response.data);
    let dataList = []
    $('div.category-wrap_iQLoo').each((index, element) => {
        const link = $(element).find('.category-wrap_iQLoo > a').attr("href");
        const imgUrl =  $(element).find('a > img').attr('src');
        const title =  $(element).find('.category-wrap_iQLoo > .content_1YWBm > a > .c-single-text-ellipsis').text().trim();
        const subtitle =  $(element).find('.hot-desc_1m_jR.small_Uvkd3').text().trim();
        const hotIndex =  $(element).find('.category-wrap_iQLoo > .trend_2RttY > .hot-index_1Bl1a').text().trim();
        dataList.push({
            'link':link,
            'imgUrl':imgUrl,
            'title':title,
            'subtitle':subtitle,
            'hotIndex':hotIndex
        })
    });
    chrome.runtime.sendMessage({ action: 'sendData', data: dataList });
    // chrome.runtime.sendMessage({'dataList': dataList});
  })
